{extend  name="manage@public/layout" /}
{block name="style"}
<style>
.ibox-content{padding:10px 20px 5px 20px !important;}
.role_man{margin-left:35px;}
.role_man ul{padding: 0;}
.role_man ul>li{list-style-type:none;float:left;margin:0 10px 10px 0;}
.regular-checkbox{display: none;}
.label-box {border: 1px solid #cacece;padding:9px;cursor: pointer;position: relative;top: 8.5px;}	
.regular-checkbox:checked+.label-box {background: url('/../../static/css/plugins/iCheck/green.png') no-repeat -48px 0px;}
</style>
{/block}
{block name="content"}
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox-title">
            <h5>编辑权限 <small></small></h5>
            <div class="ibox-tools">
                <a href="{:url('/manage/role')}" class="close-link">
                    <i class="fa fa-reply"></i>
                </a>
            </div>
        </div>
        <div class="">
            <input type="hidden" name="role_id" value="{$data['id']}" >
            {volist name="list" id="vo"}
            <div class="col-sm-12" style="padding:0 !important;">
                <div class="float-e-margins">
                    <div class="ibox-content">
                        <h4 style="padding: 0 0 5px;border-bottom: 1px solid #e7eaec;"> 
                            <input id="checkbox_{$vo.id}"  {if condition="in_array($vo.id,$data['action'])"}checked{/if} class="regular-checkbox" name="action" value="{$vo.id}" type="checkbox">
                            <label for="checkbox_{$vo.id}" class="label-box"></label>
                            &nbsp;&nbsp;&nbsp;{$vo.title} 
                        </h4>
                        {volist name="vo.children" id="v"}
                        <div class="role_man action_{$vo.id}">
                            <h5> 
                                <input id="checkbox_{$v.id}"  {if condition="in_array($v.id,$data['action'])"}checked{/if} name="action" class="action_{$vo.id} regular-checkbox" value="{$v.id}" type="checkbox">
                                <label for="checkbox_{$v.id}" class="label-box"></label>&nbsp;
                                {$v.title}  
                            </h5>
                            {notempty name="v.children"}
                            <div class="ibox-content" style="margin-left:15px;border-top: none;margin-top: -7px;">
                                <ul>
                                    {volist name="v.children" id="vs"}
                                    <li>
                                        <input name="action"  {if condition="in_array($vs.id,$data['action'])"}checked{/if} id="checkbox_{$vs.id}" class="action_{$vo.id} action_{$v.id} regular-checkbox" value="{$vs.id}" type="checkbox">
                                        <label for="checkbox_{$vs.id}" class="label-box"></label>&nbsp;
                                        {$vs.title} 
                                    </li>    
                                    {/volist}
                                    <div style="clear:both;"></div>
                                </ul>
                            </div>
                            {/notempty}
                        </div>
                        {/volist}
                    </div>
                </div>
            </div>
            {/volist}
        </div>
        <div class="col-sm-12" style="text-align:center;margin:30px 0 30px 0;">
            <button style="padding:5px 25px;" class="btn btn-primary" onclick="check()" type="button">提交保存</button>
        </div>
    </div>
    {/block}
    {block name="script"}
<script>
    //全选/反选
    $(function(){
        $(":checkbox").change(function () {
            var val_select = $(this).val();
            if($(this).is(':checked')){
                $(".action_"+val_select).prop("checked", true);
            }else{
                $(".action_"+val_select).prop("checked", false);
            }
        });
    })
    //修改
    function check(){
        var str = "";
        var id= $("input[name='role_id']").val();
        $.each($('input:checkbox:checked'),function(){
            str += $(this).val()+',';
        });
        str = str.substr(0, str.length - 1);
        //console.log(str);
        //if(str.length >= 1){
            $.post("/manage/roleEdit",{role_id:id,action:str},function(res){
                if(res.code == 1){
                    layer.msg("更新成功");
                    setTimeout(function(){
                        window.location.href=res.url;
                    },1000);
                }else{
                    layer.msg(res.msg);
                }
            })
        // }else{
        //     layer.msg("必选选择一项");
        // }
    }
</script>
 {/block}
